package edu.njust.cma.mapper;

import edu.njust.cma.pojo.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface UserMapper {

    @Select("select * from users where id = #{id}")
    User getUserInfo(Integer id);

    @Update("update users set password = #{password} where id = #{id}")
    void changePassword(Integer id, String password);

    @Update("update users set name = #{name}, email = #{email}, phone = #{phone} where id = #{id}")
    void changeUserInfo(Integer id, String name, String email, String phone);

    @Select("select * from users")
    List<User> getAllUserInfo();

    @Update("update users set resume_url = #{resumeUrl} where id = #{id}")
    void changeResume(Integer id, String resumeUrl);

    @Select("select * from users where level = #{level}")
    List<User> getUserInfoByLevel(Integer level);

    @Update("update users set level = #{level} where id = #{userId}")
    void changeUserLevel(Integer userId, Integer level);

    @Update("delete from users where id = #{userId}")
    void deleteUserById(Integer userId);

    @Update("insert into users (name,level,work_number) " +
            "values (#{name},#{level},#{workNumber})")
    void addUser(User user);

    @Select("select max(work_number) from users")
    String getMaxWorkNumber();

    @Select("select * from users where work_number = #{maxWorkNumberString}")
    User getUserByWorkNumber(String maxWorkNumberString);

    @Select("select * from users where id = #{id}")
    User getUserById(int id);
}
